<template>
  <div class="wrapper">
    <swiper :options="swiperOption" v-if="showSwiper">
      <!-- slides -->
      <swiper-slide v-for="(itemImg) in swiperImgList" :key="itemImg.id">
        <img class="swiper-img" :src="itemImg.imgUrl" />
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  // 页面进行挂载的时候，也就是还没发ajax请求的时候，swiperImgList实际是个空数组
  props: {
    swiperImgList: Array
  },
  data: function () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination'
      }
    }
  },
  computed: {
    showSwiper: function () {
      return this.swiperImgList.length
    }
  }
}

</script>

<style lang="stylus" scoped>
.wrapper {
  overflow: hidden;
  width: 100%;
  height: 0;
  padding-bottom: 26.67%;

  .swiper-img {
    width: 100%;
  }
}
</style>
